<template><view>
  <view class="errormsgDiv" v-if="nodata">
    <view class="errormsg">\（￣︶￣）/</view>
    <view class="errormsg2">没有相关数据</view>
  </view>
  <view  class="cu-list menu"  v-else> 
	 
				<view class="cu-item arrow" :key="index"  v-for="(item,index) in items"  @click="jump(item.type,item.id)">
					<view class="content padding-tb-sm">
						<view >{{item.title}}</view>
						<view class="text-gray text-sm">
							 {{item.addtime}}
						</view>
					</view>
					<view class="action"  v-if="item.pid==91">
						<view v-if="item.status == 1" class="cu-tag round bg-orange light">待处理</view>
						<view v-if="item.status == 2" class="cu-tag round bg-olive light">已受理</view>
						<view v-if="item.status == 3" class="cu-tag round bg-blue light">已关闭</view>
					</view>
				</view>
			
	</view>	
	 <view style="height: 80upx;"></view>
	<view   class="fixed-btn cu-btn block bg-blue lg"  @click="add">{{addText}}</view>
</view>

</template>
<script>
	import beeApp from '../../beeApp.js'
	export default {
		data() {
			return {
				items: [],
				page: 1,
				mounted: 0,
				nodata:0,
				loadding:0,
				userInfo:{},
				lastpage:0,
				pid:91,
				addText:'创建工单'
			}
		},
		onLoad(option) {
          // beeApp.alert("yiqwyei");
		  if(option.pid){
			  this.pid = option.pid;
		  }
		  if(this.pid ==91){
			   uni.setNavigationBarTitle({
			  	 title: '我的工单'
			  })
		  }else if(this.pid ==94){
			  uni.setNavigationBarTitle({
			  	 title: '投诉与建议'
			  })
			  this.addText = "投诉与建议";
		  }
		  
		  beeApp.getUserInfo((userInfo)=>{
			  this.userInfo = userInfo;
			  this.getTopicList();
		  })
		  
		  
		},
		onReachBottom() {
			this.getTopicList();
		},
		onPullDownRefresh() { 
			this.getTopicList(1);
			uni.stopPullDownRefresh();
		},
		onShow:function(){
			var reload = beeApp.getPageData("pages/user/topics","reload");
			if(reload==1){
				beeApp.setPageData("pages/user/topics",{reload:0});
				this.getTopicList(1);
			}
		},
		methods: {
		  getTopicList:function(reload=0){
			  var _this = this;
			  if(reload==1){
				  this.page=1;
				  this.loadding=0;
				  this.lastpage=0;
				  this.items=[];
			  }
			   var params = {
				    page: this.page,
					user_id:this.userInfo.user_id,
					pid:this.pid
			   };
			 if ( this.loadding ==1 || this.lastpage==1) {
				   return false;
			   }
			   _this.loadding=1;
			   beeApp.api("/sns/topic/list", params, function(res) {
						_this.loadding=0;
                        if (res.code != 200) {
                            beeApp.alert(res.msg);
                            return;
                        }
                        // console.log(res);
                        if (res.data.list.length === 0) {
                            _this.lastpage = 1;
                        }

                        var items = _this.items;
                        _this.items = items.concat(res.data.list);
                        _this.page++;
                        if(_this.items.length === 0){
                            _this.nodata=1;
                        }else{
							_this.nodata=0;
						}
                    });
		  },
		  add:function(){
			  if(this.pid==91){
				   uni.navigateTo({
						url:"/pages/topic/addworkorder"
					})
			  }else if(this.pid==94){
				   uni.navigateTo({
						url:"/pages/topic/report"
					})
			  }
			 		
		  },
		  jump:function(type,id){
                if(type=='vote'){
					uni.navigateTo({
						url:"/pages/vote/detail?id="+id
					})			
                }else{
                    uni.navigateTo({
						url:"/pages/topic/detail?id="+id
					})	
                }
            },
	   }
		
}
</script>


<style>
</style>
